package com.yupi.springbootinit.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yupi.springbootinit.service.UserInterfaceInfoService;
import model.entity.UserInterfaceInfo;
import service.InnerUserInterfaceInfoService;

import javax.annotation.Resource;

/**
 * @author 25169
 */
@Service(version = "${dubbo.service.version}")
public class InnerUserInterfaceInfoServiceImpl implements InnerUserInterfaceInfoService {

    @Resource
    private UserInterfaceInfoService userInterfaceInfoService;

    @Override
    public boolean invoke(long interfaceInfoId, long userId) {
        return userInterfaceInfoService.invoke(interfaceInfoId,userId);

    }

    @Override
    public boolean invoke2(long interfaceInfoId,long userId){
        LambdaQueryWrapper<UserInterfaceInfo> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(UserInterfaceInfo::getInterfaceInfoId,interfaceInfoId);
        queryWrapper.eq(UserInterfaceInfo::getUserId,userId);
        UserInterfaceInfo one = userInterfaceInfoService.getOne(queryWrapper);
        if(one==null){
            UserInterfaceInfo userInterfaceInfo=new UserInterfaceInfo();
            userInterfaceInfo.setLeftNum(30);
            userInterfaceInfo.setUserId(userId);
            userInterfaceInfo.setInterfaceInfoId(interfaceInfoId);
            userInterfaceInfoService.save(userInterfaceInfo);
        }
        Integer leftNum = one.getLeftNum();
        return leftNum>0;
    }
}
